// LemCoop
// Copyright (C) 2013  Oliver Naumann <bldrax@gmail.com>

// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include "groundmask.h"

GroundMask::GroundMask(int size_x, int size_y)
{
	m_mask = new char[size_x * size_y];

	m_size_x = size_x;
	m_size_y = size_y;

	// Fill the array with open space.
	for (int i = 0; i < m_size_x; i++)
	{
		for (int j = 0; j < m_size_y; j++)
		{
			SetPixel(i, j, Types::AIR);
		}
	}
}

GroundMask::~GroundMask()
{
	delete m_mask;
}

bool GroundMask::SetPixel(int x, int y, char value)
{
	if (x < m_size_x && y < m_size_y)
	{
		m_mask[x + m_size_x * y] = value;
		return true;
	}

	return false;
}

bool GroundMask::GetPixel(int x, int y, char &value)
{
	if (x < m_size_x && y < m_size_y)
	{
		value = m_mask[x + m_size_x * y];
		return true;
	}

	return false;
}